Conversation
millerdev
left a comment
There was a problem hiding this comment.
Zero performance impact when enabled: Check overhead <1μs
Is this always true? Is this AI-generated PR description content? Seems like the entire Backwards Compatibility section could be removed or replaced with a single line: "The new features added in this PR are opt-in and do not break backward compatibility."
This PR seems unnecessarily verbose—and I didn't even read the whole plan doc, which feels wrong because it's slated to be kept in the repo. Wading through AI slop is tiring. The time savings gained by using AI seem to have translated to extra review time. That's frustrating.
- Add audit_enabled context variable - Add is_audit_enabled() check function - Add disable_audit() and enable_audit() context managers - Update __all__ exports
- Add check to _decorate_db_write for save/delete - Add check to _m2m_changed_handler for M2M changes
- Add check to audit_field_changes - Add check to create_audit_event
- Add check to bulk_create - Add check to delete - Add check to update
- Test setting-based disable - Test context manager disable/enable - Test M2M field auditing - Test QuerySet operations - Test thread safety - Test backwards compatibility - Test migration scenarios
- Update global disable tests to use correct model names - Fix test isolation issues - Simplify thread safety test to avoid Django transaction complexity - All 200 tests now pass
- Add FIELD_AUDIT_ENABLED to settings table - Add Disabling Auditing section with examples - Document disable_audit() and enable_audit() context managers - Include use cases for tests, migrations, and imports
6e97e9c to
4eb7d1f
Compare
|
@millerdev apologies for the rebase, I wasn't thinking. |
millerdev
left a comment
There was a problem hiding this comment.
@millerdev apologies for the rebase, I wasn't thinking.
Looks like the plan doc was somehow completely removed in the rebase, and surprisingly I don't even see it removed in the before/after rebase compare view (although it's in the previous branch history). I guess that's fine.
Maybe I missed it, but I think there is no attribution to AI code generation anywhere in this PR anymore. How do you think about that? Is it reasonable to not mention when AI is used to write code?
I thought the original commits had co-authorship - but maybe not since I rebased. I've added a note at the top of the PR description. |
Note
This code was originally written by Claude AI
Summary
Adds the ability to globally disable auditing in django-field-audit, providing both application-wide control via Django settings and fine-grained runtime control via context managers. This feature is particularly useful for unit tests, data migrations, bulk imports, and maintenance operations where audit overhead is not needed.
Implementation
Core Infrastructure
contextvarsfor thread-safe, async-safe state managementis_audit_enabled()checks context variable first, then falls back to Django settingdisable_audit()andenable_audit()for runtime controlAPI
New public API exports:
New Django setting:
Usage Examples
Global Disable via Setting
Runtime Disable
Override Global Setting
Use Cases
Unit Tests - Improve performance by skipping audit overhead:
Data Migrations - Skip auditing during bulk operations:
Backwards Compatibility
The new features added in this PR are opt-in and do not break backward compatibility.